using Microsoft.AspNetCore.Mvc;
using JTZY.Model.Visit.Dto;
using JTZY.Model.Visit;
using JTZY.Service.Visit.IVisitService;
using JTZY.Admin.WebApi.Filters;

//创建时间：2025-03-16
namespace JTZY.Admin.WebApi.Controllers.Visit
{
    /// <summary>
    /// 用户访问记录
    /// </summary>
    [Verify]
    [Route("visit/Uservisit")]
    public class UservisitController : BaseController
    {
        /// <summary>
        /// 用户访问记录接口
        /// </summary>
        private readonly IUservisitService _UservisitService;

        public UservisitController(IUservisitService UservisitService)
        {
            _UservisitService = UservisitService;
        }

        /// <summary>
        /// 查询用户访问记录列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        [HttpGet("list")]
        [ActionPermissionFilter(Permission = "uservisit:list")]
        public IActionResult QueryUservisit([FromQuery] UservisitQueryDto parm)
        {
            parm.UserId = HttpContext.GetUId();
            var response = _UservisitService.GetList(parm);
            return SUCCESS(response);
        }


        [HttpGet("statistics")]
        [ActionPermissionFilter(Permission = "uservisit:list")]
        public IActionResult Uservisitstatistics([FromQuery] UservisitQueryDto parm)
        {
            parm.UserId =HttpContext.GetUId();
            var response = _UservisitService.Statistics(parm);
            return SUCCESS(response);
        }

        /// <summary>
        /// 查询用户访问记录详情
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet("{Id}")]
        [ActionPermissionFilter(Permission = "uservisit:query")]
        public IActionResult GetUservisit(long Id)
        {
            var response = _UservisitService.GetInfo(Id);
            
            var info = response.Adapt<UservisitDto>();
            return SUCCESS(info);
        }

        /// <summary>
        /// 添加用户访问记录
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ActionPermissionFilter(Permission = "uservisit:add")]
        [Log(Title = "用户访问记录", BusinessType = BusinessType.INSERT)]
        public IActionResult AddUservisit([FromBody] UservisitDto parm)
        {
            var modal = parm.Adapt<Uservisit>().ToCreate(HttpContext);

            var response = _UservisitService.AddUservisit(modal);

            return SUCCESS(response);
        }

        /// <summary>
        /// 更新用户访问记录
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        [ActionPermissionFilter(Permission = "uservisit:edit")]
        [Log(Title = "用户访问记录", BusinessType = BusinessType.UPDATE)]
        public IActionResult UpdateUservisit([FromBody] UservisitDto parm)
        {
            var modal = parm.Adapt<Uservisit>().ToUpdate(HttpContext);
            var response = _UservisitService.UpdateUservisit(modal);

            return ToResponse(response);
        }

        /// <summary>
        /// 删除用户访问记录
        /// </summary>
        /// <returns></returns>
        [HttpPost("delete/{ids}")]
        [ActionPermissionFilter(Permission = "uservisit:delete")]
        [Log(Title = "用户访问记录", BusinessType = BusinessType.DELETE)]
        public IActionResult DeleteUservisit([FromRoute]string ids)
        {
            var idArr = Tools.SplitAndConvert<long>(ids);

            return ToResponse(_UservisitService.Delete(idArr));
        }

    }
}